/*
 * Copyright (C) 2011 Nicola Bonzanni
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package nl.vu.few.ibivu.jlemon;

import nl.vu.few.ibivu.jlemon.concepts.Graph;
import nl.vu.few.ibivu.jlemon.concepts.Node;


public class NodeIterator<N extends Node & Comparable<N>> extends AbstractIterator<N> {
	private Graph<N,?> graph;

	/**
	 * An iterator initialized with this constructor will behave as a
	 * standard java iterator, i.e. the state of the iterator before calling
	 * next() is undefined and the first call to next() will return the
	 * <b>first</b> node in the graph. If you desire an iterator that
	 * represent the first node in the graph and such that the first call to
	 * next() returns the <b>second</b> node of the graph, you should use
	 * <tt>NodeIterator(graph.firstNode())</tt> instead.
	 * @param graph TODO
	 * 
	 * @see #NodeIterator(Node)
	 * @see Graph#firstNode()
	 */
	public NodeIterator(Graph<N,?> graph) {
		super(null, graph.firstNode());
		this.graph = graph;
	}

	/**
	 * An iterator initialized with this constructor represent the given
	 * node until the next() function is called. The first call to next()
	 * will return the node next to the given one, and will set the iterator
	 * to represent the returned node accordingly.
	 * 
	 * @param node
	 *            a node belonging to the given graph
	 * @param graph TODO
	 * @see #NodeIterator()
	 */
	public NodeIterator(Graph<N,?> graph, N node) {
		super(node,  graph.next(node));
		this.graph = graph;
	}

	@Override
	protected N computeNext() {
		return graph.next(current);
	}
}